#include <models/ChannelMananger.h>
#include <algorithm>

void ChannelManager::add_channel(std::unique_ptr<BaseChannel>& channel)
{
    channels_.push_back(std::move(channel));
}

std::unique_ptr<BaseChannel> ChannelManager::get_channel(const std::string& sn)
{
    auto it = std::find_if(channels_.begin(), channels_.end(),
        [&sn](const std::unique_ptr<BaseChannel>& channel) {
            return channel->get_sn() == sn;
        });
    
    if (it != channels_.end()) {
        auto target = std::move(*it);
        channels_.erase(it);
        return target;
    }
    return nullptr;
}